// 封装chrome.storage.local.set
export const setLocalStorage = (data) => {
    return new Promise((resolve, reject) => {
        chrome.storage.local.set(data, function () {
            if (chrome.runtime.lastError) {
                reject(chrome.runtime.lastError)
            } else {
                resolve('set success')
            }
        })
    })
}

// 封装chrome.storage.local.get

export const getLocalStorage = (keys) => {
    return new Promise((resolve, reject) => {
        chrome.storage.local.get(keys, function (result) {
            if (chrome.runtime.lastError) {
                reject(chrome.runtime.lastError)
            } else {
                console.log('chrome.storage.local.get:"' + keys + '"', result)
                resolve(result[keys])
            }
        })
    })
}

// 封装chrome.storage.local.remove
export const removeLocalStorage = (keys) => {
    return new Promise((resolve, reject) => {
        chrome.storage.local.remove(keys, function () {
            if (chrome.runtime.lastError) {
                reject(chrome.runtime.lastError)
            } else {
                resolve('remove success')
            }
        })
    })
}

// 封装chrome.storage.local.clear
export const clearLocalStorage = () => {
    return new Promise((resolve, reject) => {
        chrome.storage.local.clear(function () {
            if (chrome.runtime.lastError) {
                reject(chrome.runtime.lastError)
            } else {
                resolve('clear success')
            }
        })
    })
}
